<%@page import="com.surelution.projects.crm.NoGasTypeCategory"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>
<resource:dateChooser />
<g:set var="entityName" value="${message(code: 'market.label', default: 'market')}" />
<g:javascript library="jquery"/>
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.printElement.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/datechooser',file:'datechooser.js')}"></script>
<title><g:message code="default.cardSaleReport.label" /></title>
	<script type="text/javascript">
		$(document).ready(function() {
		   $("#simplePrint").click(function() {
		       printElem({leaveOpen: true, printMode: 'popup', overrideElementCSS: ["${resource(dir:'plugins/richui-0.8/css',file:'calendarmonthview.css')}","${resource(dir:'css',file:'main.css')}"]});
		   });
		});
		function printElem(options){
		    $('#monthReport').printElement(options);
		};

	</script>
</head>

<body>
  <div class="body">
          <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
          </div>
          <div>
        	<g:form action="cardSaleReport">
				<p style="font-size:16px;color:#000;margin:10px 0;"><g:message code="default.cardSaleReport.label" /></p>
        		选择日期：<richui:dateChooser locale="zh" name="startDay" format="yyyy-MM-dd" value="${startDay}"/>至<richui:dateChooser locale="zh" name="endDay" format="yyyy-MM-dd" value="${endDay}" />
			    <span class="menuButton" style="margin-right:5px;"><g:actionSubmit value="${message(code: 'default.button.search.label', default: 'search')}" action="cardSaleReport"/></span><br>
    			选择片区：
				<g:each in="${com.surelution.projects.crm.StationArea.list()}" var="area">
	    			<g:checkBox id="stationArea.id_${area.id }" name="stationArea" value="${area.id }" checked="${stationArea!=[]?stationArea.contains(area.id):true}"/><label for="stationArea.id_${area.id }">${area.areaName}</label>&nbsp;
    			</g:each>
  			    <span class="menuButton"><g:actionSubmit value="${message(code: 'default.button.export.label', default: 'Export')}" action="cardSaleReportExport"/></span>
			    <input type="button" value="打印报表" id="simplePrint" />
			</g:form>
			<g:if test="${flash.message}">
            	<div class="message">${flash.message}</div>
            </g:if>
        </div>
        
  		<g:if test="${result}">
        <div id="monthReport" style="height:650px;overflow:auto;">
			<p style="font-size:16px;color:#000;margin:10px 0;">报表日期:${startDay.format("yyyy.MM.dd")}到${endDay.format("yyyy.MM.dd") }</p>
        		<table>
	        		<tr>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:50px;">片区</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:150px;">加油站名</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">新增开卡张数</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">新增开卡总购油量(L)</td>
	    			</tr>
    				<g:each in="${result}" var="r" status="i">
					<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
    					<td style="text-align:center;"> ${r[0][0].stationArea.areaName}</td>
    					<td> ${r[0][0].shortName }</td>
    					<td style="text-align:center;"> ${r[0][1]}</td>
    					<td style="text-align:center;"><g:formatNumber number="${r[0][2]}" maxFractionDigits="2"/></td>
    				</tr>
    				</g:each>
          	</table>
        </div>
    	</g:if>

  </div>
</body>
</html>